﻿Public Class CTokenStd
    Inherits CTokenBase

    Protected mnumId As Int32
    Protected mstrText As String
    Protected mnumPosBeg As Int32
    Protected mnumLength As UInt32

    Public Overrides ReadOnly Property Id As Integer
        Get
            Return mnumId
        End Get
    End Property

    Public Overrides ReadOnly Property PosBeg As Int32
        Get
            Return mnumPosBeg
        End Get
    End Property

    Public Overrides ReadOnly Property Length As UInt32
        Get
            Return mnumLength
        End Get
    End Property

    Public Overrides ReadOnly Property Text As String
        Get
            Return mstrText
        End Get
    End Property

    Public Sub New(numId_i As Int32, numPosBeg_i As Int32, numLength_i As UInt32, strText_i As String)
        mnumId = numId_i
        mstrText = strText_i
        mnumPosBeg = numPosBeg_i
        mnumLength = numLength_i
    End Sub

    Public Sub New(numId_i As Int32, numPosBeg_i As Int32, numLength_i As UInt32)
        mnumId = numId_i
        mstrText = Nothing
        mnumPosBeg = numPosBeg_i
        mnumLength = numLength_i
    End Sub
End Class

Public Class CTokenDesignerQuotedLiteral
    Inherits CTokenDesignerBase

    Protected mstrTextRaw As String
    Protected mstrText As String
    Protected mnumPosBeg As Int32
    Protected mnumPosEnd As Int32
    Protected mnumId As Int32

    Public ReadOnly Property Text As String
        Get
            Return mstrText
        End Get
    End Property

    Public Property Id As Int32
        Get
            Return mnumId
        End Get
        Set(num_i As Int32)
            mnumId = num_i
        End Set
    End Property

    Public ReadOnly Property PosBeg As Int32
        Get
            Return mnumPosBeg
        End Get
    End Property

    Public ReadOnly Property PosEnd As Int32
        Get
            Return mnumPosEnd
        End Get
    End Property

    Public Sub New(ByVal strTextRaw_i As String, ByVal numPosBeg_i As Int32, ByVal numId_i As Int32)
        If String.IsNullOrEmpty(strTextRaw_i) Then
            Throw New ArgumentNullException("strTextRaw_i")
        End If

        If numPosBeg_i < 0 OrElse numPosBeg_i >= strTextRaw_i.Length Then
            Throw New ArgumentOutOfRangeException("numPosBeg_i")
        End If

        mnumId = numId_i
        mnumPosBeg = numPosBeg_i
        mnumPosEnd = mnumPosBeg
        mstrText = String.Empty
        mstrTextRaw = strTextRaw_i
    End Sub

    Public Sub New(ByVal strTextRaw_i As String, ByVal numPosBeg_i As Int32)
        MyClass.New(strTextRaw_i, numPosBeg_i, 0)
    End Sub

    Public Overloads Function Assemble() As CTokenBase
        Return New CTokenStd(mnumId, mnumPosBeg, CUInt(mnumPosEnd - mnumPosBeg), mstrText)
    End Function

    Public Overrides Function Assemble(objConnector_i As CTokenBase) As CTokenBase
        mstrText = mstrText + mstrTextRaw.Substring(mnumPosEnd, objConnector_i.PosBeg - mnumPosEnd)
        mnumPosEnd = objConnector_i.PosBeg

        Return New CTokenStd(mnumId, mnumPosBeg, CUInt(mnumPosEnd - mnumPosBeg), mstrText)
    End Function

    Public Overrides Sub PartAdd(objPart_i As CTokenBase)
        mstrText = mstrText + mstrTextRaw.Substring(mnumPosEnd, objPart_i.PosBeg - mnumPosEnd) + objPart_i.Text
        mnumPosEnd = objPart_i.PosBeg + CInt(objPart_i.Length)
    End Sub
End Class

Public Class CTokenFactoryQuotedLiteral
    Inherits CTokenFactoryStd

    Public Overrides Function NewDesigner(strTextRaw_i As String, numPosBeg_i As Integer) As NSTZWackyParcer.CTokenDesignerBase
        Return New CTokenDesignerQuotedLiteral(strTextRaw_i, numPosBeg_i, mnumId)
    End Function
End Class


Public Class CTokenDesignerStd
    Inherits CTokenDesignerBase

    Protected mnumId As Int32
    Protected mnumPosBeg As Int32
    Protected mnumPosEnd As Int32
    Protected mstrTextRaw As String
    Protected mcllChild As NSCllG.List(Of CTokenBase)

    Public Property Id As Int32
        Get
            Return mnumId
        End Get
        Set(num_i As Int32)
            mnumId = num_i
        End Set
    End Property

    Public Property PosBeg As Int32
        Get
            Return mnumPosBeg
        End Get
        Set(num_i As Int32)
            If num_i > mnumPosEnd Then
                Throw New ArgumentException("PosBeg must be not greather of PosEnd.", "PosBeg")
            End If

            mnumPosBeg = num_i
        End Set
    End Property

    Public Property PosEnd As Int32
        Get
            Return mnumPosEnd
        End Get
        Set(num_i As Int32)
            If num_i < mnumPosBeg Then
                Throw New ArgumentException("PosBeg must be not greather of PosEnd.", "PosBeg")
            End If

            mnumPosEnd = num_i
        End Set
    End Property

    Public ReadOnly Property ChildCll As NSCllG.List(Of CTokenBase)
        Get
            Return mcllChild
        End Get
    End Property

    Public Overloads Function Assemble() As CTokenBase
        Return New CTokenComplexStd(mnumId, mcllChild, mnumPosBeg, CUInt(mnumPosEnd - mnumPosBeg))
    End Function

    Public Overrides Function Assemble(objConnector_i As CTokenBase) As CTokenBase
        mnumPosEnd = objConnector_i.PosBeg
        mnumId = objConnector_i.Id

        Return New CTokenComplexStd(mnumId, mcllChild, mnumPosBeg, CUInt(mnumPosEnd - mnumPosBeg))
    End Function

    Public Overrides Sub PartAdd(objPart_i As CTokenBase)
        mcllChild.Add(objPart_i)
    End Sub

    Public Sub New(ByVal strTextRaw_i As String, ByVal numPosBeg_i As Int32)
        mnumPosBeg = numPosBeg_i
        mnumPosEnd = numPosBeg_i
        mstrTextRaw = strTextRaw_i
        mnumId = 0
        mcllChild = New NSCllG.List(Of CTokenBase)
    End Sub

    Public Sub New(ByVal strTextRaw_i As String, ByVal numPosBeg_i As Int32, ByVal numId_i As Int32)
        mnumPosBeg = numPosBeg_i
        mnumPosEnd = numPosBeg_i
        mstrTextRaw = strTextRaw_i
        mnumId = numId_i
        mcllChild = New NSCllG.List(Of CTokenBase)
    End Sub
End Class

Public Class CTokenComplexStd
    Inherits CTokenBase

    Protected mnumId As Int32
    Protected mnumPosBeg As Int32
    Protected mnumLength As UInt32
    Protected mcllChil As NSCllG.ICollection(Of CTokenBase)

    Public Overrides ReadOnly Property Id As Integer
        Get
            Return mnumId
        End Get
    End Property

    Public Overrides ReadOnly Property PosBeg As Integer
        Get
            Return mnumPosBeg
        End Get
    End Property

    Public Overrides ReadOnly Property Length As UInt32
        Get
            Return mnumLength
        End Get
    End Property

    Public ReadOnly Property ChildCll As NSCllG.ICollection(Of CTokenBase)
        Get
            Return mcllChil
        End Get
    End Property

    Public Sub New(numId_i As Int32, cllChil_i As NSCllG.ICollection(Of CTokenBase), numPosBeg_i As Int32, numLength_i As UInt32)
        mnumId = numId_i
        mcllChil = cllChil_i
        mnumPosBeg = numPosBeg_i
        mnumLength = numLength_i
    End Sub
End Class
